package com.sunnay.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DataValidator {

    public DataValidator() {
    }

    public static boolean isIntege(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^-?[1-9]\\d*$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isIntegePositive(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[1-9]\\d*$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isVagueIntegePositive(Double value) {
        if (value < 0.0) {
            return false;
        } else {
            Long longValue = BigDecimalUtil.multiply2Long(value.toString(), "100");
            return longValue % 100L <= 0L;
        }
    }

    public static boolean isIntegeNegtive(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^-[1-9]\\d*$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isNum(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^([+-]?)\\d*\\.?\\d+$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isNumPositive(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[1-9]\\d*|0$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isNumNegtive(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^-[1-9]\\d*|0$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isDecmal(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^([+-]?)\\d*\\.\\d+$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isDecmalPositive(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isDecmalNegtive(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*)$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isDecmal3(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^-?([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0)$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isDecmal4(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isDecmal5(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^(-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*))|0?.0+|0$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isEmail(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isColor(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[a-fA-F0-9]{6}$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isUrl(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^http[s]?:\\/\\/([\\w-]+\\.)+[\\w-]+([\\w-./?%&=]*)?$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isChinese(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isContainChinese(String value) {
        Pattern p = null;
        Matcher m = null;
        p = Pattern.compile("[\\u4E00-\\u9FA5\\uF900-\\uFA2D]");
        m = p.matcher(value);
        return m.find();
    }

    public static boolean isAscii(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[\\x00-\\xFF]+$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isZipcode(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^\\d{6}$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isMobile(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^(0|86|17951)?(13[0-9]|14[056789]|15[012356789]|16[6]|17[345678]|18[0-9]|19[89])[0-9]{8}$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isIp(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isNotempty(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^\\S+$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isPicture(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("(.*)\\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isRar(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("(.*)\\.(rar|zip|7zip|tgz)$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isDate(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isQq(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[1-9]*[1-9][0-9]*$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isTel(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^(([0\\+]\\d{2,3}-)?(0\\d{2,3})-)?(\\d{7,8})(-(\\d{3,}))?$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isUsername(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^\\w+$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isLetter(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[A-Za-z]+$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isLetter_u(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[A-Z]+$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isLetter_l(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[a-z]+$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isPrice(String value) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^([1-9]{1}[0-9]{0,}(\\.[0-9]{0,2})?|0(\\.[0-9]{0,2})?|\\.[0-9]{1,2})$");
        m = p.matcher(value);
        b = m.matches();
        return b;
    }

    public static boolean isContainSpecialChar(String value) {
        String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>\\-\\[\\]/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？<>～｀＄＾＋＝｜＜＞￥×]";
        Pattern p = Pattern.compile(regEx);
        Matcher matcher = p.matcher(value);
        boolean b = matcher.find();
        return b;
    }

    public static boolean isCharlength(String value, int set) {
        return getCharlength(value) == set;
    }

    public static int getCharlength(String value) {
        int[] res = new int[4];
        int sum = 0;
        char[] var3 = value.toCharArray();
        int var4 = var3.length;

        int var5;
        int c;
        for(var5 = 0; var5 < var4; ++var5) {
            c = var3[var5];
            int var10002;
            if (c <= 90 && c >= 65 || c <= 122 && c >= 97) {
                var10002 = res[0]++;
            } else if (c <= 57 && c >= 48) {
                var10002 = res[1]++;
            } else if (c == 32) {
                var10002 = res[2]++;
            } else {
                res[3] += 2;
            }
        }

        int[] var7 = res;
        var4 = res.length;

        for(var5 = 0; var5 < var4; ++var5) {
            c = var7[var5];
            sum += c;
        }

        return sum;
    }

    public static int getCharlengthAndSpecial(String value) {
        int[] res = new int[5];
        int sum = 0;
        char[] var3 = value.toCharArray();
        int var4 = var3.length;

        int var5;
        int c;
        for(var5 = 0; var5 < var4; ++var5) {
            c = var3[var5];
            int var10002;
            if (c <= 90 && c >= 65 || c <= 122 && c >= 97) {
                var10002 = res[0]++;
            } else if (c <= 57 && c >= 48) {
                var10002 = res[1]++;
            } else if (c == 32) {
                var10002 = res[2]++;
            } else if (isContainSpecialChar(String.valueOf((char)c))) {
                var10002 = res[3]++;
            } else {
                res[4] += 2;
            }
        }

        int[] var7 = res;
        var4 = res.length;

        for(var5 = 0; var5 < var4; ++var5) {
            c = var7[var5];
            sum += c;
        }

        return sum;
    }

    public static String removeFourChar(String content) {
        byte[] conbyte = content.getBytes();

        for(int i = 0; i < conbyte.length; ++i) {
            if ((conbyte[i] & 248) == 240) {
                for(int j = 0; j < 4; ++j) {
                    conbyte[i + j] = 48;
                }

                i += 3;
            }
        }

        content = new String(conbyte);
        return content;
    }

    public static String removeInterpunction(String value) {
        return value.replaceAll("[\\pP+~$`^=|<>～｀＄＾＋＝｜＜＞￥×]", "");
    }

    public static boolean isEvenNumber(Integer value) {
        return value % 2 == 0;
    }

    public static boolean isDecimal(String value, int several) {
        if (several <= 0) {
            return false;
        } else {
            String[] a = new String[]{"", "10", "100", "1000"};
            return BigDecimalUtil.multiply2Long(value, a[several]) % (long)Integer.valueOf(a[several]) == 0L;
        }
    }
}
